define(function(require, exports){
	// var $ = require('jquery');
	var pubjs = require('pubjs');
	var grid  = require('@base/highGrid');
	var util = require('util');

	var SweetyGrid = grid.base.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'sweety/list',
					param: {
						'IsDeleted': 0
						,'order' :'impressions|-1,clicks|-1'
					},
					cols: [
						{name:'_id',text:"ID", sort: true, width: 60, align: 'center'},
						'SweetyNameWithThumb'
					],
					// subs: ['creative', 'whisky', 'mediaAndAd', 'period', 'frequency', 'region', 'client', 'campaign', 'product'],
					default_metrics : pubjs.config('defaultMetrics'),
					reqType: 'websocket',
					gridName: 'sweety',
					subFilter: 'subFilter'
				}
			);

			if(util.exist(this.parseSubsCondition(config), 'whisky')){
				util.extend(true, config.get(), {
					'tab':{'cost': null, 'front': null}
				});
			}

			this.Super('init', arguments);
		},
		subFilter: function(subs, data){
			var c = this.getConfig();
			var condition = c.param.condition;
			if(!condition){return;}
			var parentIsCampaign = condition.match("campaign");

			util.each(subs, function(sub){
				// 如果父级是活动，则当前创意包数据下不应再有活动子表格
				if (sub.type === 'campaign'){
					sub.iconBtn.toggle(!parentIsCampaign);
				}
			});
		}
	});
	exports.base = SweetyGrid;

	// 创意包子表格
	var SubSweetyGrid = SweetyGrid.extend({
		init: function(config){
			config = pubjs.conf(config, {
					subs: ['creative', 'whisky', 'mediaAndAd', 'period', 'frequency', 'region', 'client', 'campaign', 'product']
				}
			);
			this.Super('init', arguments);
		},
	});
	exports.subSweetyGrid = SubSweetyGrid;
});